|
|
|
|
|
|
|
Printer.ScaleMode = vbPixels
Printer.PSet (0, 0)
r.Right= Printer.ScaleWidth
r.Bottom = Printer.ScaleHeight
res = OleDraw(obj, Aspects(cmbAspect.ListIndex), Printer.hDC, r)
If res <> 0 Then
Err.Raise res
End If
Printer.EndDoc
End Function |
|
|
|
|
|
|
|
|
Printing that single pixel tells Visual Basic that a printing operation has occurred, so it will correctly initialize the device context and will print the page when the EndDoc method is called. You will now see a beautiful full-page calendar page printed.2 |
|
|
|
|
|
|
|
|
You may have noticed that the Microsoft MonthView control is able to scale itself to print into the rectangle you provide, whereas the private control written in Visual Basic lacks this ability. This is actually one of the limitations of Visual Basicit does not provide your control with any mechanism to determine the rectangle provided to the OleDraw function. You can use the ActiveX extension technology in version 6 of Desaware's SpyWorks to detect this rectangle and even override the IViewObject drawing operation, thus allowing your control to scale itself in the same way as the MonthView control. |
|
|
|
|
|
|
|
|
Also, don't be surprised if this function does not work with every ActiveX control. Even though every ActiveX control is supposed to implement IViewObject correctly, many of them make assumptions internally that prevent them from working with arbitrary device contexts. |
|
|
|
|
|
|
|
|
Although this puzzle is in the OLE section, it really belongs more in the "Rocket Science" section that follows, because all of the problems faced in solving this puzzle are subtle and require a broad understanding of Windows. Few Visual Basic programmers work extensively with the OLE APIit is indeed complex. But there are many hidden gems, such as this one, that are available to Visual Basic programmers who are willing to dig through the nearly incomprehensible documentation. |
|
|
|
 |
|
 |
|
|
2 Beautiful, in this sense, does not refer to the aesthetic quality of the image drawn, which admittedly leaves something to be desired. Instead, it refers to the fact that virtually any image would look gorgeous after the frustration you probably felt trying to figure out the solution to this puzzle. |
|
|
|
|
|